//
//  GWShopDetailCell.m
//  GiftWanted
//
//  Created by lanou on 15/11/12.
//  Copyright © 2015年 陈文杰. All rights reserved.
//

#import "GWShopDetailCell.h"
#import "GWItemsCollectionViewCell.h"
#import "GWItemViewController.h"

@interface GWShopDetailCell () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate>

@end


@implementation GWShopDetailCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-100)];
        [self.contentView addSubview:_webView];
        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.minimumInteritemSpacing = 5;
        layout.minimumLineSpacing = 5;
        layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
        layout.itemSize = CGSizeMake((SCREEN_WIDTH-15)/2, (SCREEN_WIDTH-15)/2+75);
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-100) collectionViewLayout:layout];
        _collectionView.backgroundColor = [UIColor clearColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor colorWithWhite:0.913 alpha:1.000];
        [_collectionView registerClass:[GWItemsCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
        [self.contentView addSubview:_collectionView];
        
    }
    return self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataSourceArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    GWItemsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.contentView.backgroundColor = [UIColor whiteColor];
    GWHotItemsModel *model = _dataSourceArray[indexPath.item];
    [cell setConfigureModel:model];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    GWHotItemsModel *model = _dataSourceArray[indexPath.item];
    GWItemViewController *itemVC = [[GWItemViewController alloc] init];
    itemVC.id_s = model.id_s;
    [self.naviC pushViewController:itemVC animated:YES];
}

- (void)setShopModel:(GWShopDetailModel *)shopModel {
    
    [_collectionView reloadData];
    _shopModel = shopModel;
    [_webView loadHTMLString:shopModel.intro_html baseURL:[NSURL fileURLWithPath:[NSBundle mainBundle].bundlePath]];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
